package com.tarena.security.admin.service.impl;


import com.tarena.security.admin.entity.db.Strategy;
import com.tarena.security.admin.entity.db.UserRole;
import com.tarena.security.admin.param.StrategyParam;
import com.tarena.security.admin.param.UpdateStrategyParam;
import com.tarena.security.admin.param.UserRoleParam;
import com.tarena.security.admin.persists.repository.StrategyRepository;
import com.tarena.security.admin.persists.repository.UserRoleRepository;
import com.tarena.security.admin.service.IStrategyService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 策略表格 服务实现类
 * </p>
 *
 * @author Ly
 * @since 2023-04-10
 */
@Service

@Slf4j
public class StrategyServiceImpl implements IStrategyService {
    @Autowired
    StrategyRepository strategyRepository;

    @Override
    public int insertOne(StrategyParam strategyParam) {

        Strategy strategy=new Strategy();
        BeanUtils.copyProperties(strategyParam,strategy);
//        strategy.setGmtCreate(System.currentTimeMillis());
        log.info("新增用户与角色关系数据:{}",strategy);
        int num=strategyRepository.insertOne(strategy);
        return num;
    }

    @Override
    public Strategy selectOne(Integer Id) {
        Strategy strategy=strategyRepository.selectOne(Id);

        return strategy;
    }

    @Override
    public int deteleOneById(Integer Id) {
        int num=strategyRepository.deteleOneById(Id);
        return num;
    }

    @Override
    public int updateByStrategy(UpdateStrategyParam updateStrategyParam) {
        strategyRepository.selectOne(updateStrategyParam.getId());
        Strategy strategy=new Strategy();
        BeanUtils.copyProperties(updateStrategyParam,strategy);
        log.info("修改用户和角色关系数据:{}",strategy);
        int num=strategyRepository.updateByStrategy(strategy);
        return num;
    }
}
